package com.dao;


import com.entity.Admins;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Description: 管理员dao  // 类说明，在创建类时要填写
 * @ClassName: AdminsDao    // 类名，会自动填充
 * @Author: weisn          // 创建者
 * @Date: 2020/12/8 11:34   // 时间
 * @Version: 1.0     // 版本
 */

public interface AdminsDao {

    /**
     * 管理员登录判断
     * @param username
     * @param password
     * @return
     */
    @Select("select * from wenyu_admin where username=#{username} and password=#{password}")
    public Admins selectByAdminNameAndPassword(@Param("username")String username, @Param("password") String password);

    /**
     * 查询所有管理员账户
     * @return
     */
    @Select("select * from wenyu_admin")
    public List<Admins> selectList();

    /**
     * 添加账户
     * @param username
     * @param password
     * @return
     */
    @Insert("insert into wenyu_admin(username,password) values(#{username},#{password})")
    @SelectKey(keyProperty = "id" , statement = "SELECT LAST_INSERT_ID()",before = false,resultType = Integer.class)
    boolean adminsinsert(@Param("username")String username,@Param("password")String password);

    /**
     * 删除账户
     * @param id
     * @return
     */
    @Update("delete from wenyu_admin where id=#{id}")
    boolean adminlistupdate(int id);

    /**
     * 通过id查找
     * @param id
     * @return
     */
    @Select("select * from wenyu_admin where id=#{id}")
    public Admins select(int id);

    /**
     * 通过id修改账户
     * @param id
     * @param password
     * @return
     */
    @Update("update wenyu_admin set password=#{password} where id=#{id}")
    public boolean adminUpdate(@Param("id")int id,@Param("password")String password);

    /**
     * 自增重置
     */
    @Update("ALTER TABLE wenyu_admin AUTO_INCREMENT = 1" )
    public boolean alter();
}
